# @summary A short summary of the purpose of this class
#
# A description of what this class does
#
# @example
#   include lzu::gridwn9
class lzu::gridwn9 (
  $has_gpu = "no",
  $allowusers = ["root"],
  )
  {

  $startd_soft_config = '/etc/condor/config.d/01-startd.conf'
  $startd_hard_config = '/etc/condor/config.d/01-startd-hard.conf'

  $condor_pkg = [
      "condor",
      "condor-classads",
      "condor-kbdd",
      "condor-procd",
      "condor-externals",
      "python3-condor",
      "python3-scitokens",
  ]
  yumrepo { "condor":
    baseurl => "http://${mirrorserver}/yum/condor/repo/10.x/el${operatingsystemmajrelease}/x86_64/release",
    descr => "condor",
    enabled => 1,
    gpgcheck => 0,
    priority => 20,
    before   => Yumrepo['site'],
  }

  package { $condor_pkg:
    ensure  => installed,
    require => Yumrepo['site'],
  } ->
  package {"condor-worker":
    ensure     => absent,
  } ->
  file {"/etc/condor/wrapper":
    ensure     =>  directory,
    mode       =>  '0755',
    owner      =>  'root',
    group      =>  'root',
  } ->
file {"/etc/condor/wrapper/wrapper.sh":
    mode       =>  '0755',
    owner      =>  'root',
    group      =>  'root',
    source     =>  "puppet:///modules/${module_name}/wrapper_tmp.sh",
    notify   => Exec['refresh_condor_wn']
  } ->
  file {"/etc/condor/config.d/01-startd.conf":
    mode       =>  '0644',
    owner      =>  'root',
    group      =>  'root',
    source     =>  "puppet:///modules/${module_name}/01-startd-grid.conf",
    notify   => Exec['refresh_condor_wn']
  } ->
  file {"/etc/condor/config.d/01-startd-hard.conf":
    mode       =>  '0644',
    owner      =>  'root',
    group      =>  'root',
    content    =>  template("${module_name}/01-startd-hard-grid.erb"),
    notify   => Exec['refresh_condor_wn']
  } ->
  file {"/etc/condor/config.d/02-gpu-start.conf":
    mode       =>  '0644',
    owner      =>  'root',
    group      =>  'root',
    content    =>  template("${module_name}/02-gpu-start.erb"),
    notify   => Exec['refresh_condor_wn']
  } ->
  service { 'condor':
    ensure     => 'running',
    enable     => true,
    hasrestart => true,
    hasstatus  => true,
  }
  exec {'restart_condor_wn':
    command      => "/usr/bin/systemctl restart  condor",
    refreshonly  => true
  }

  exec {'refresh_condor_wn':
    command      => "/usr/sbin/condor_reconfig",
    refreshonly  => true
  }
  # disable other users
  #sshd_config { 'AllowUsers':
  #  ensure => present,
  #  value  => $allowusers,
  #  notify => Service['sshd'],
  #}

  cron { 'clean-scratch':
    command => "ls -al /scratch/ |grep -v  ' root '|grep -v condor|awk '{print \$9}'|xargs -I {} find /scratch/{} -maxdepth 1 -mtime +14  |xargs rm -rf",
    user    => 'root',
    hour    => 4,
    minute  => 33
  }
}
